<?php 
session_start();
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) 
{
    // last request was more than 30 minates ago
    session_destroy();   // destroy session data in storage
    session_unset();     // unset $_SESSION variable for the runtime
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp

require("include/connect.php");
							
if(isset($_REQUEST['id']))
			$cart_id=$_REQUEST['id'];
		else
		    $cart_id=1;
		
		if(isset($_REQUEST['action']))
			$action=$_REQUEST['action'];
		else
		    $action="none";
switch($action)
		{
			case "add":
			
					$_SESSION['cart'][$cart_id] = array('id' =>$cart_id,'qty'=> 1);
				
			break;
			case "update":
			
					$_SESSION['cart'][$cart_id] = array('id' =>$cart_id,'qty'=> $_GET['qty']);
			
			break;
			case "wishadd":
					if(isset($_SESSION['CID'])){
						$checkkk = mysqli_query($con,"SELECT * FROM wishlist WHERE CustomerID='$_SESSION[CID]' and ProductID='$_POST[id]'");
						
						if(mysqli_num_rows($checkkk) == 0)
						{
							$ccdata=mysqli_query($con,"insert into wishlist(WishID, CustomerID , ProductID) values('', '$_SESSION[CID]', '$_POST[id]')");
							echo "success";
						}
						
					}else{
						echo "failure";
					}
			case "remove":
				if(isset($_SESSION['cart'][$cart_id]))
				{
					$_SESSION['cart'][$cart_id]--;
					
					//if($_SESSION['cart'][$cart_id]==0)
						unset($_SESSION['cart'][$cart_id]);
				}
				
			case "wish_remove":
				$CID=$_SESSION['CID'];
				$id=$_REQUEST['id'];
				$sql="delete from wishlist where ProductID='$id' and CustomerID='$CID'"; 
				mysqli_query($con,$sql);
			break;
			case "empty":
				unset($_SESSION['cart']);
			break;
		}
		
	
?>